/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Line;

import Chiabai_total.RotatedJLabel;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;

/**
 *
 * @author Oho
 */
public class Bullet extends Thread {
    // speed is in units/second
    // angle is in radians

    private static final double SPEED = 0.1;
    int x1, y1, x2, y2;
    RotatedJLabel lb;
    //jframe 
    //truyen vao jframe main 
    //them vao tham so input loai danh bai len hay gom bai ,
    //khai bao 1 bien de luu loai lai 
    int type;
    public Bullet(RotatedJLabel lb, int x1, int y1, int x2, int y2) {
        this.x1 = x1;
        this.x2 = x2;
        this.y1 = y1;
        this.y2 = y2;
        this.lb = lb;
    }

    

    public void run() {

        double angle = Math.atan2(y2 - y1, x2 - x1);
        double x = x1, y = y1;

        while (true) {
            
                x += SPEED * Math.cos(angle);
                y += SPEED * Math.sin(angle);
                System.out.println(x + ", " + y);
                lb.setBounds((int) x, (int) y, 100, 100);
              
                if((int)(x+0.5)==x2&&(int)(y+0.5)==y2)//dieu kien de dung lai 
                {//main xoa no di 
                    //neu danh bai len 
                    this.stop();
                    break;
                    //nguoc lai
                }
            
        }

    }
}
